package com.demo.inner;

import cn.hutool.json.JSONUtil;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpMenuService;
import me.chanjar.weixin.cp.bean.WxCpAgent;

/**
 * created by lanxinghua@2dfire.com on 2020/2/13
 * 企业内部开发：应用管理
 */
public class InnerAppDoDemo extends InnerBaseService{
    static WxCpAgentService agentService = wxCpService.getAgentService();
    static WxCpMenuService menuService = wxCpService.getMenuService();

    public static void main(String[] args) throws Exception{
        // getAgentInfo(agentId);
        menuList();
        menuCreate();
    }


    /**
     * 获取应用信息
     * @param agentId
     * @throws Exception
     */
    public static void getAgentInfo(Integer agentId) throws Exception{
        WxCpAgent cpAgent = agentService.get(agentId);
        System.out.println(JSONUtil.toJsonStr(cpAgent));

        // 设置应用信息
        //agentService.set(null);
    }


    /**
     * 菜单管理：获取菜单
     * @throws Exception
     */
    public static void menuList() throws Exception{
        WxMenu wxMenu = menuService.get(agentId);
        System.out.println(JSONUtil.toJsonStr(wxMenu));
    }


    /**
     * 删除菜单
     * @throws Exception
     */
    public static void menuDel() throws Exception {
        menuService.delete(null);
    }

    public static void menuCreate() throws Exception {
        WxMenu menu = menuService.get(agentId);
        menuService.create(agentId, menu);
    }

}
